﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Automobile.service.Common;
using Automobile.service.DAL;
using Automobile.service.Model;
using System.Data;
using System.Data.SqlClient;

namespace Automobile.service.DAL
{
    public class WareHoseDAL
    {
        SQLHelper helper = new SQLHelper();
        /// <summary>
        /// 仓库管理——显示
        /// </summary>
        /// <returns></returns>
        public DataTable ShowListWareHose()
        {
            string sql = "select WareHose_Id,WareHose_Name,WareHose_People,WareHose_Phone,WareHose_Address,WareHose_Remark from WareHose";
            return helper.ExecDataTable(sql);
        }
        /// <summary>
        /// 仓库管理——获取总行数
        /// </summary>
        /// <returns></returns>
        public int GetWareHoseCount()
        {
            string sql = "select Count(WareHose_Id) from WareHose";
            return Convert.ToInt32(helper.ExecScalar(sql));
        }
        /// <summary>
        /// 仓库管理——添加
        /// </summary>
        /// <param name="w"></param>
        /// <returns></returns>
        public int AddWareHose(WareHose w)
        {
            SqlParameter[] addwarehose ={
                                         new SqlParameter("@WareHose_Name",SqlDbType.VarChar,100),
                                         new SqlParameter("@WareHose_People",SqlDbType.VarChar,100),
                                         new SqlParameter("@WareHose_Phone",SqlDbType.VarChar,100),
                                         new SqlParameter("@WareHose_Address",SqlDbType.VarChar,100),
                                         new SqlParameter("@WareHose_Remark",SqlDbType.VarChar,100)
                                     };
            addwarehose[0].Value = w.WareHose_Name;
            addwarehose[1].Value = w.WareHose_People;
            addwarehose[2].Value = w.WareHose_Phone;
            addwarehose[3].Value = w.WareHose_Address;
            addwarehose[4].Value = w.WareHose_Remark;
            string sql = "insert into WareHose(WareHose_Name,WareHose_People,WareHose_Phone,WareHose_Address,WareHose_Remark) values(@WareHose_Name,@WareHose_People,@WareHose_Phone,@WareHose_Address,@WareHose_Remark)";
            return helper.ExecNonquery(sql,addwarehose);
        }
        
        /// <summary>
        /// 仓库管理——删除支持多删
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public int DelWareHose(string id)
        {
            string sql = "delete from WareHose where WareHose_Id in (" + id + ")";
            return helper.ExecNonquery(sql);
        }
        
        /// <summary>
        /// 仓库管理——根据仓库名称搜索
        /// </summary>
        /// <param name="wname"></param>
        /// <returns></returns>
        public DataTable GetWareHoseByName(string wname)
        {
            string sql = "select WareHose_Id,WareHose_Name,WareHose_People,WareHose_Phone,WareHose_Address,WareHose_Remark from WareHose where WareHose_Name like '%"+wname+"%'";
            return helper.ExecDataTable(sql);
        }
        /// <summary>
        /// 仓库管理——根据编号获取信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public DataTable GetWareHoseByid(int id)
        {
            string sql = "select WareHose_Id,WareHose_Name,WareHose_People,WareHose_Phone,WareHose_Address,WareHose_Remark from WareHose where WareHose_Id="+id;
            return helper.ExecDataTable(sql);
        }
        /// <summary>
        /// 仓库管理——修改仓库信息
        /// </summary>
        /// <param name="w"></param>
        /// <returns></returns>
        public int UpdWareHose(WareHose w)
        {
            string sql = "update WareHose set WareHose_Name='"+w.WareHose_Name+"',WareHose_People='"+w.WareHose_People+"',WareHose_Phone='"+w.WareHose_Phone+"',WareHose_Address='"+w.WareHose_Address+"',WareHose_Remark='"+w.WareHose_Remark+"' where WareHose_Id="+w.WareHose_Id;
            return helper.ExecNonquery(sql);
        }
        
    }
}
